package org.xfy.ymcc.consumer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.netty.util.Constant;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import org.xfy.common.constant.Constants;
import org.xfy.common.constant.HttpStatus;
import org.xfy.common.constant.RocketConstants;

import java.io.UnsupportedEncodingException;

@Component
@RocketMQMessageListener(consumerGroup = "service-common-emailmessage-consumer",
        //Topic
        topic = RocketConstants.COURSE_SEND_EMAIL_TOPIC,
        //TAGS
        selectorExpression = RocketConstants.COURSE_SEND_EMAIL_TAG
)
public class EmailMessageMQConsumer implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            String string = new String(messageExt.getBody(), Constants.UTF8);
            JSONObject object = JSON.parseObject(string);
            Object id = object.get("id");
            Object content = object.get("content");
            //调用邮箱工具类
            System.out.println(id.toString()+"收到了"+content.toString());
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

    }
}
